<template>
  <div>
    <!-- 内容 -->
    <div
      class="dark-body"
      v-show="contentShow"
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="busy"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="true"
    >
      <div
        class="dark-body-content"
        v-for="con in orderDataList"
        :key="con.id"
        @click="goOrderDetails(con.id)"
      >
        <div class="content-order">
          <span class="box_left">订单号：{{ con.number }}</span>
          <span class="box_right">{{ con.status }}</span>
        </div>
        <hr />
        <div class="dark-content" v-for="item in con.details" :key="item.id">
          <div class="dark-cont-img box_left">
            <div
              :style="{ backgroundImage: 'url(' + item.picture + ')' }"
            ></div>
          </div>
          <div class="cont-list-right box_right">
            <h4>{{ item.headline }}</h4>
            <p>规格：{{ item.gauge }}</p>
            <div>
              <span class="box_left">*{{ item.number }}</span>
              <span class="box_right">￥{{ item.price }}</span>
            </div>
          </div>
        </div>
      </div>
      <p v-show="infiniteMsgShow" class="tips">加载下一页</p>
      <p v-show="!infiniteMsgShow" class="tips">没有更多数据</p>
    </div>
    <div v-if="!contentShow">
      <p class="empty">暂时没找到相应的订单</p>
    </div>
  </div>
</template>

<script>
import { Indicator } from "mint-ui";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      busy: true,
      page: 0,
      limit: 10,
      contentShow: "",
      infiniteMsgShow: true,
      orderDataList: []
    };
  },
  created() {
    this.loadMore();
  },
  methods: {
    // 当属性滚动的时候  加载  滚动加载
    loadMore() {
      this.busy = true; // 将无限滚动给禁用
      setTimeout(() => {
        //发送请求有时间间隔第一个滚动时间结束后才发送第二个请求
        this.page++; //滚动之后加载第二页
        this.selectOrderList();
      }, 500);
    },
    selectOrderList() {
      //我的订单--完成
      Indicator.open({ spinnerType: "fading-circle" });
      let me = this;
      this.$axios
        .post(
          "/api/home/myOrderGoods",
          {
            uid: localStorage.uid,
            page: this.page,
            limit: this.limit
          },
          { emulateJSON: true }
        )
        .then(kun => {
          console.log(kun);
          Indicator.close();

          let listTotal = kun.total;
          if (listTotal > 0) {
            me.contentShow = true;
          } else {
            me.contentShow = false;
          }
          me.orderDataList = me.orderDataList.concat(kun.data);
          let DownloadTotal = me.page * me.limit;
          let total = kun.total;

          if (DownloadTotal > total) {
            me.busy = true; // 将无限滚动关闭
            me.page = 0; // 页数变为0
            me.infiniteMsgShow = false; // 切换底部提示信息
          } else {
            me.busy = false; // 当还有多余的数据时，将无限滚动给打开 ，就是可以继续滚动去请求后台
            me.infiniteMsgShow = true;
          }

          if (kun.code != 200) {
            Toast(kun.msg);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    goOrderDetails(val) {
      localStorage.or_id = val;
      //到详情页
      this.$router.push({
        name: "OrderDetails",
        params: { or_id: val }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
h4,
p {
  margin: 0;
  padding: 0;
}
//下拉 没有数据
.empty {
  font-size: 0.875rem;
  color: #999999;
  text-align: center;
  margin-top: 5.25rem;
}
//下拉 加载下一页
.tips {
  font-size: 0.875rem;
  color: #999999;
  text-align: center;
  margin: 1.25rem 0;
}
.box_left {
  float: left;
}
.box_right {
  float: right;
}
.dark-body {
  margin-top: 3.5rem;
}
// 内容
.dark-body-content {
  width: 21.5625rem;
  margin: 0 auto;
  .content-order {
    height: 1.9375rem;
    box-shadow: 0 0 0 0.0625rem rgba(0, 0, 0, 0.05);

    span {
      font-size: 0.75rem;
      padding: 0.625rem 0.625rem 0;
      color: rgba(51, 51, 51, 1);
    }
    span.box_right {
      color: rgba(255, 0, 0, 1);
    }
  }
  hr {
    width: 20.3125rem;
    height: 0.0625rem;
    background-color: rgba(233, 231, 231, 1);
    margin: 0 auto;
    border: none;
  }
  .dark-content {
    width: 21.5625rem;
    height: 7.5rem;
    margin: 0 auto;
    box-shadow: 0 0 0 0.0625rem rgba(0, 0, 0, 0.05);
    margin-bottom: 0.625rem;
    .dark-cont-img {
      width: 4.6875rem;
      height: 6.25rem;
      margin-top: 0.625rem;
      margin-left: 0.625rem;
      :first-child {
        width: 4.6875rem;
        height: 6.25rem;
        border-radius: 0.3125rem;

        background-image: url(../../assets/shop/spimg.png);
        background-repeat: no-repeat;
        background-size: cover;
        background-position: center;
        overflow: hidden;
      }
    }
    .cont-list-right {
      width: 15rem;
      height: 6.25rem;
      position: relative;
      margin-top: 0.625rem;
      margin-right: 0.625rem;
      h4 {
        font-size: 1rem;
        color: rgba(26, 26, 26, 1);
        line-height: 1.25rem;
      }
      p {
        margin: 0;
        font-size: 0.75rem;
        color: rgba(153, 153, 153, 1);
        line-height: 0.78125rem;
        margin-top: 0.625rem;
      }
      div {
        position: absolute;
        bottom: 0;
        width: 100%;

        span {
          font-size: 0.9375rem;
          color: rgba(255, 32, 0, 1);
        }
      }
    }
  }
}
</style>
